from django.contrib.auth.mixins import LoginRequiredMixin, AccessMixin
from django.http import JsonResponse


# 方式一
# class LoginRequiredJsonMixin(AccessMixin):
#     def dispatch(self, request, *args, **kwargs):
#         if not request.user.is_authenticated:
#             return JsonResponse({"code":400, "errmsg":"用户未登录"})
#         return super().dispatch(request, *args, **kwargs)


# 方式二
class LoginRequiredJsonMixin(LoginRequiredMixin):
    def handle_no_permission(self):
        return JsonResponse({"code":400, "errmsg":"用户未登录"})

